<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Kết quả tìm kiếm</title>
<style type="text/css">
<!--
.style1 {	font-size: 24px;
	font-weight: bold;
	
}
.style3 {font-size: 18px}
.style4 {font-weight: bold}
.style6 {font-size: 18px; font-weight: bold; }
-->
</style>
</head>

<body bgcolor="#330000">
<for>
<?php  
	include_once($_SERVER['DOCUMENT_ROOT']."/mba/ketnoiCSDL.php"); 
?>
<p align="center" class="style1"><font color="red">THÔNG TIN CƠ BẢN </font></p>
<?php
		session_start();
		$from="may_bien_ap a";
		$where="";
		if($_SESSION["donvi"]=="" && $_SESSION["tram"]=="" && $_SESSION["tinhtrang"]==""){
			$where.="CONG_SUAT like '".$_SESSION["congsuat"]."'";
		}
		else if($_SESSION["donvi"]=="" && $_SESSION["tram"]==""){
			$from.=",tinh_trang_may b";
			$where.="a.SO_N0=b.SO_N0 and CONG_SUAT like '".$_SESSION["congsuat"]."' and b.TEN_TINH_TRANG_MAY='".$_SESSION["tinhtrang"]."'";
		}
		else if($_SESSION["donvi"]=="" && $_SESSION["tinhtrang"]==""){
			$from.=",mba_tram b";
			$where.="a.SO_N0=b.SO_N0 and CONG_SUAT like '".$_SESSION["congsuat"]."'and b.MA_TRAM like '".$_SESSION["tram"]."'";
		}
		else if($_SESSION["tram"]=="" && $_SESSION["tinhtrang"]==""){
			$from.=",chi_tiet_so_huu b";
			$where.="a.SO_N0=b.SO_N0 and CONG_SUAT like '".$_SESSION["congsuat"]."'and b.MA_DON_VI like '".$_SESSION["donvi"]."'";
		}
		else if($_SESSION["donvi"]==""){
			$from.=",mba_tram b, tinh_trang_may c";
			$where.="a.SO_N0=b.SO_N0 and a.SO_N0=c.SO_N0 and CONG_SUAT like '".$_SESSION["congsuat"]."' and b.MA_TRAM like '".$_SESSION["tram"]."' and c.TEN_TINH_TRANG_MAY='".$_SESSION["tinhtrang"]."'";			
		}
		else if($_SESSION["tram"]==""){
			$from.=",chi_tiet_so_huu b, tinh_trang_may c";
			$where.="a.SO_N0=b.SO_N0 and a.SO_N0=c.SO_N0 and CONG_SUAT like '".$_SESSION["congsuat"]."' and b.MA_DON_VI like '".$_SESSION["donvi"]."' and c.TEN_TINH_TRANG_MAY ='".$_SESSION["tinhtrang"]."'";
		}
		else if($_SESSION["tinhtrang"]==""){
			$from.=",chi_tiet_so_huu b, mba_tram c";
			$where.="a.SO_N0=b.SO_N0 and a.SO_N0=c.SO_N0 and CONG_SUAT like '".$_SESSION["congsuat"]."' and b.MA_DON_VI like '".$_SESSION["donvi"]."' and c.MA_TRAM= '".$_SESSION["tram"]."'";
		}
		else{
			$from.=",chi_tiet_so_huu b, mba_tram c, tinh_trang_may d";
			$where.="a.SO_N0=b.SO_N0 and a.SO_N0=c.SO_N0 and a.SO_N0 = d.SO_N0 and CONG_SUAT like '".$_SESSION["congsuat"]."' and b.MA_DON_VI like '".$_SESSION["donvi"]."' and c.MA_TRAM like '".$_SESSION["tram"]."' and d.TEN_TINH_TRANG_MAY='".$_SESSION["tinhtrang"]."'";
		}
		
		$sql="select distinct a.SO_N0, e.CAP_DIEN_AP,CONG_SUAT,CHIEU_DAI,CHIEU_RONG,CHIEU_CAO,DAU_MAY,RUOT_MAY,TONG,TEN_NSX,TEN_NUOC,THONG_SO_DO,DIA_CHI_NSX, NAM_SX, NAM_NHAP_VE,NHAN_XET,GHI_CHU from ".$from.",loai_dien_ap e, nha_sx f where a.MA_DIEN_AP=e.MA_DIEN_AP and a.MA_NSX=f.MA_NSX and ".$where;
	
		$result=mysql_query($sql,$link);
	
	
?>
<table width="1538" height="188" border="1">
  <tr style="background-color:">
    <td width="32"><span class="style6"><font color="#FFFFFF">STT</span></td>
    <td width="26" height="66"><div align="center" class="style4 style3"><font color="#FFFFFF"><strong>Số N0</strong></div></td>
    <td width="47"><div align="center" class="style4 style3"><font color="#FFFFFF"><strong>Loại điện áp (U)</strong></div></td>
    <td width="53"><div align="center" class="style4 style3"><font color="#FFFFFF"><strong>Công suất (S)</strong></div></td>
    <td width="55"><div align="center" class="style4 style3"><font color="#FFFFFF"><strong>Chiều dài<br />
    (cm)</strong></div></td>
    <td width="55"><span class="style4 style3"><font color="#FFFFFF"><strong>Chiều rộng<br />
    (cm)</strong></span></td>
    <td width="67"><div align="center" class="style4 style3"><font color="#FFFFFF"><strong>Chiều cao(cm) </strong></div></td>
    <td width="40"><div align="center" class="style4 style3"><font color="#FFFFFF"><strong>Đầu máy<br />
    (kg)</strong></div></td>
    <td width="47"><div align="center" class="style4 style3"><font color="#FFFFFF"><strong>Ruột máy<br />
    (kg)</strong></div></td>
    <td width="44"><div align="center" class="style4 style3"><font color="#FFFFFF"><strong>Tổng<br />
    (kg)</strong></div></td>
    <td width="52"><div align="center" class="style4 style3"><font color="#FFFFFF"><strong>Hãng sản xuất</strong></div></td>
    <td width="56"><div align="center" class="style4 style3"><font color="#FFFFFF"><strong>N&#432;&#7899;c <br />
    s&#7843;n xu&#7845;t</strong></div></td>
    <td width="64" height="66"><div align="center" class="style4 style3"><font color="#FFFFFF"><strong>Lo&#7841;i d&#7847;u </strong></div></td>
    <td width="72" height="66"><div align="center" class="style4 style3"><font color="#FFFFFF"><strong>Th&ocirc;ng s&#7889; &#273;o </strong></div></td>
    <td width="81" height="66"><div align="center" class="style4 style3"><font color="#FFFFFF"><strong>Th&ocirc;ng tin li&ecirc;n h&#7879; nh&agrave; s&#7843;n xu&#7845;t </strong></div></td>
    <td width="85"><div align="center"><span class="style3"><font color="#FFFFFF"><strong>N&#259;m s&#7843;n xu&#7845;t </strong></span></div></td>
    <td width="85"><div align="center" class="style3"><font color="#FFFFFF"><strong>Năm nhập về</strong> </div></td>
    <td width="85"><div align="center"><span class="style6"><font color="#FFFFFF">Đơn vị hiện đang sở hữu </span></div></td>
    <td width="85"><div align="center"><span class="style6"><font color="#FFFFFF">Trạm</span></div></td>
    <td width="85"><div align="center"><span class="style6"><font color="#FFFFFF">Tình trạng máy </span></div></td>
    <td width="85" height="66"><div align="center" class="style4 style3"><strong>Nh&#7853;n x&eacute;t </strong></div></td>
    <td width="101"><div align="center" class="style4 style3"><strong>Ghi ch&uacute;</strong></div></td>
  </tr>
  <?php
  		if(mysql_num_rows($result)!=0)
  			{
			$stt=0;
  			while($row=mysql_fetch_array($result))
			{				
				$c1=$row["SO_N0"];
				$c2=$row["CAP_DIEN_AP"];
				$c3=$row["CONG_SUAT"];
				$c4=$row["CHIEU_DAI"];
				$c5=$row["CHIEU_RONG"];
				$c6=$row["CHIEU_CAO"];
				$c7=$row["DAU_MAY"];
				$c8=$row["RUOT_MAY"];
				$c9=$row["TONG"];
				$c10=$row["TEN_NSX"];
				$c11=$row["TEN_NUOC"];
			
				$c13=$row["THONG_SO_DO"];
				$c14=$row["DIA_CHI_NSX"];
				$c17=$row["NAM_SX"];	
				$c21=$row["NAM_NHAP_VE"];			
				$c15=$row["NHAN_XET"];
				$c16=$row["GHI_CHU"];
				$c18="";
				$c19="";
				$c20="";				
			//Lay ten don vi co ngay chuyen den gan nhat		
			$sql2="Select distinct a.MA_DON_VI, TEN_DON_VI from chi_tiet_so_huu a, don_vi b where a.MA_DON_VI=b.MA_DON_VI and a.SO_N0='".$c1."' and NGAY_CHUYEN_DEN=(select max(NGAY_CHUYEN_DEN) from chi_tiet_so_huu where SO_N0='".$c1."')";
			$result2=mysql_query($sql2,$link);
			$row2=mysql_fetch_array($result2);
			$c18.=$row2["TEN_DON_VI"];
			$donvi=$row2["MA_DON_VI"];
			//lay ten tram co ngay van hanh gan nhat				
			$sql3="select distinct a.MA_TRAM, TEN_TRAM from mba_tram a, tram b where a.MA_TRAM=b.MA_TRAM and SO_N0='".$c1."' and NGAY_VAN_HANH=(Select max(NGAY_VAN_HANH) from mba_tram where SO_N0='".$c1."')";
			$result3=mysql_query($sql3,$link);
			$row3=mysql_fetch_array($result3);
			$c19.=$row3["TEN_TRAM"];
			$tram=$row3["MA_TRAM"];
			
			//lay ten tinh trang gan day nhat
			$sql0="select distinct TEN_TINH_TRANG_MAY from tinh_trang_may where SO_N0='".$c1."' and NGAY_CO_TINH_TRANG=(select max(NGAY_CO_TINH_TRANG) from tinh_trang_may where SO_N0='".$c1."')";
			$result0=mysql_query($sql0,$link);
			if(mysql_num_rows($result0)!=0){
				$row0=mysql_fetch_array($result0);	
				$c20.=$row0["TEN_TINH_TRANG_MAY"];	
			}	
			//kiem tra don vi so huu hien tai cua mba
				if($_SESSION["donvi"]==""){
					if(($_SESSION["tram"]=="")||($_SESSION["tram"]!="" && $tram==$_SESSION["tram"])){		
					$stt++;			
					echo "<tr style='background-color:#FFFFFF'><td style='background-color:#330000'><font color='#FFFFFF'><b>$stt</b></td>";
					echo "<td>$c1</td>";
					echo "<td>$c2</td>";
					echo "<td>$c3</td>";
					echo "<td>$c4</td>";
					echo "<td>$c5</td>";
					echo "<td>$c6</td>";
					echo "<td>$c7</td>";
					echo "<td>$c8</td>";
					echo "<td>$c9</td>";
					echo "<td>$c10</td>";
					echo "<td>$c11</td>";
					echo "<td>  </td>";
					echo "<td>$c13</td>";
					echo "<td>$c14</td>";
					echo "<td>$c17</td>";
					echo "<td>$c21</td>";
					echo "<td>$c18</td>";
					echo "<td>$c19</td>";
					echo "<td>$c20</td>";
					echo "<td>$c15</td>";
					echo "<td>$c16</td>";
					}
					
					
				
				}
				else if($_SESSION["donvi"]!=""){
					
					if(($_SESSION["tram"]=="" && $donvi==$_SESSION["donvi"])||($_SESSION["tram"]!="" && $donvi==$_SESSION["donvi"] && $tram==$_SESSION["tram"])){				
						$stt++;			
						echo "<tr style='background-color:#FFFFFF'><td style='background-color:#330000'><font color='#FFFFFF'><b>$stt</b></td>";
						echo "<td>$c1</td>";
						echo "<td>$c2</td>";
						echo "<td>$c3</td>";
						echo "<td>$c4</td>";
						echo "<td>$c5</td>";
						echo "<td>$c6</td>";
						echo "<td>$c7</td>";
						echo "<td>$c8</td>";
						echo "<td>$c9</td>";
						echo "<td>$c10</td>";
						echo "<td>$c11</td>";
						echo "<td>  </td>";
						echo "<td>$c13</td>";
						echo "<td>$c14</td>";
						echo "<td>$c17</td>";
						echo "<td>$c21</td>";
						echo "<td>$c18</td>";
						echo "<td>$c19</td>";
						echo "<td>$c20</td>";
						echo "<td>$c15</td>";
						echo "<td>$c16</td>";
					}
					
				}
			}
		}
      
  ?>
</table>
<p></p>
</body>
</html>
